<template>
  <div class="Personalized">
    <div class="Oneself" v-if="Oneself.name">
      <p class="titleFont">{{ Oneself.name }}</p>
      <div v-for="item in Oneself.result" :key="item.id">
        <img :src="item.picUrl" alt="" />
        <p>{{ item.copywriter }}</p>
      </div>
    </div>
    <div class="newMusic">
      <p class="titleFont">最新音乐</p>
      <div v-for="(item, i) in NewMusic" :key="item.id">
        <!-- 播放图标 -->
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-bofang1"></use>
        </svg>
        <p>{{ i + 1 }}</p>
        <img :src="item.picUrl" alt="" />
        <div class="write">
          <p>{{ item.name }}</p>
          <p>{{ item.song.album.company }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive } from "vue";
import { useSendReq } from "@/store/sendReq";
// 主题
const SendReq = useSendReq();
const Oneself = reactive<resPrivate<Oneself[]>>({
  name: "",
  result: [],
});
const NewMusic = reactive<NewMusic[]>([]);
// 独家放送
SendReq.getPrivate().then((res) => {
  Oneself.name = res.name;
  Oneself.result.push(...res.result);
});
// 最新音乐
!NewMusic.length &&
  window.addEventListener("scroll", () => {
    if (!NewMusic.length && window.scrollY >= 233) {
      SendReq.getNewMusic().then((res) => {
        NewMusic.length = 0;
        NewMusic.push(...res.result);
      });
    }
  });
</script>

<style lang="less" scoped>
.Personalized {
  .Oneself {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    width: 100%;
    > .titleFont {
      width: 100%;
      flex: 100%;
    }
    > div {
      width: 32%;
      height: 200px;
      img {
        width: 100%;
        height: 200px;
        object-fit: contain;
      }
      > p {
        margin: 10px;
      }
    }
  }
  .newMusic {
    margin-top: 50px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    .titleFont {
      flex: 100%;
      width: 100%;
      padding-bottom: 20px;
      border-bottom: 1px solid #b8b6b6;
    }

    > div {
      position: relative;
      > .icon {
        position: absolute;
        left: 7%;
        transform: translateX(-6%);
        font-size: 30px;
      }
      margin-bottom: 20px;
      flex: 49%;
      display: flex;
      align-items: center;
      padding-left: 10px;
      > img {
        width: 65px;
        height: 65px;
        margin: 0 20px;
      }
      > div {
        height: 65px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
      }
    }
  }
}
</style>
